﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DS.Controls
{
    public partial class DSClientListItem : DSkin.DirectUI.DuiBaseControl
    {
        public Common.ClientItemData clientItemData;

        public bool selected = false;

        public string Ip {
            get => clientItemData.ipEndPoint;
            set {
                clientItemData.ipEndPoint = value;
                this.duiLabel1.Text = clientItemData.ipEndPoint;
            }
        }

        public Common.ClientItemState State {
            get => clientItemData.clientItemState;
            set
            {
                clientItemData.clientItemState = value;
                this.duiLabel2.Text = clientItemData.clientItemState.ToString() ;

                if(clientItemData.clientItemState == Common.ClientItemState.busy)
                {
                    this.duiIcon1.Visible = true;
                }
                else
                {
                    this.duiIcon1.Visible = false;
                }
            }
        }

        public DSClientListItem()
        {
            InitializeComponent();
        }

        public DSClientListItem(Common.ClientItemData clientItemData)
        {
            InitializeComponent();
            this.clientItemData = clientItemData;
            this.duiLabel1.Text = clientItemData.ipEndPoint;
        }

        public DSClientListItem(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }


        private void DSListBoxItem_IsSelectedChanged(object sender, EventArgs e)
        {
            if (this.IsSelected)
            {
                //this.BackgroundImage = Properties.Resources.list_item_select;
                this.BackgroundRender.BackgroundBrush = SelectedColor;
                this.duiCheckBox1.CheckState = System.Windows.Forms.CheckState.Checked;
            }
            else
            {
                //this.BackgroundImage = null;
                this.BackgroundRender.BackgroundBrush = BaseColor;
                this.duiCheckBox1.CheckState = System.Windows.Forms.CheckState.Unchecked;
            }
        }

        private void DSListBoxItem_MouseEnter(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (this.IsSelected)
            {
                this.BackgroundRender.BackgroundBrush = SelectedHoverColor;
            }
            else
            {
                this.BackgroundRender.BackgroundBrush = HoverColor;
            }
        }

        private void DSListBoxItem_MouseLeave(object sender, EventArgs e)
        {
            if (this.IsSelected)
            {
                this.BackgroundRender.BackgroundBrush = SelectedColor;
            }
            else
            {
                this.BackgroundRender.BackgroundBrush = BaseColor;
            }
        }


    }
}
